package com.nkym.wypan.listener;/*
 * @ClassName FileDeleteListener
 * @Desc TODO
 * @Author 19637
 * @Date 2023/7/7 22:45
 * @Version 1.0
 */

import com.nkym.wypan.event.FileDeleteEvent;
import com.nkym.wypan.model.entity.UserFile;
import com.nkym.wypan.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class FileDeleteListener {

    @Autowired
    UserInfoService userInfoService;
    @EventListener(FileDeleteEvent.class)
    public void freeUpUserSpace(FileDeleteEvent event) {
        List<UserFile> userFileList = event.getUserFileList();
        long freeSize = 0;
        for (UserFile userFile : userFileList) {
            freeSize += userFile.getFileSize();
        }
        userInfoService.freeUpUseSpace(freeSize);
    }
}
